<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@include file="../common/header.jsp"%>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar">
        <div class="wu-toolbar-button">
            <%@include file="../common/menus.jsp"%>
        </div>
        <div class="wu-toolbar-search">
            <label>订单id:</label><input id="search-id" class="wu-text" style="width:100px">
            <a href="#" id="search-btn" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="data-datagrid" class="easyui-datagrid" toolbar="#wu-toolbar"></table>
</div>
</div>
<%@include file="../common/footer.jsp"%>

<!-- End of easyui-dialog -->
<script type="text/javascript">
	
	
/**
* 删除记录
*/
function remove(){
	var item = $('#data-datagrid').datagrid('getSelections');
	if(item == null || item.length == 0){
		$.messager.alert('信息提示','请选择要删除的数据！','info');
		return;
	}
	$.messager.confirm('信息提示','确定要删除这<font color="red">'+item.length+'</font>条订单记录？', function(result){
		if(result){
			var ids = '';
			for(var i=0;i<item.length;i++){
				ids += item[i].id + ',';
			}
			$.ajax({
				url:'delete_orders',
				dataType:'json',
				type:'post',
				data:{ids:ids},
				success:function(data){
					$("#data-datagrid").datagrid('clearSelections');
					if(data.type == 'success'){
						$.messager.alert('信息提示','删除成功！','info');
						$('#data-datagrid').datagrid('reload');
					}else{
						$.messager.alert('信息提示',data.msg,'warning');
					}
				}
			});
		}	
	});
}

	
	
	//使field能够点接
	function formatterPoint(value, rec, index){
	
		var field = this.field;
		
		var rs = eval("rec['"+field.replace(/\./g,"']['")+"']");  
		 
		rs = String(rs); //如果rs不是字符串类型数据，需要强转String类型，不然下面substring会报错的。
		
		var sub_rs = rs.substring(rs.length-4,rs.length)
	
		 
		if(".jpg" == sub_rs  || ".jpeg" == sub_rs || ".png" == sub_rs || ".gif" == sub_rs)
		{
			var img = '<img src="'+rs+'" width="50px" height="50px"/>';
			return img;
		}else{
			
			return rs;
		}
	}
	
	
	//搜索按钮监听
	$("#search-btn").click(function(){
		var option = {id:$("#search-id").val()};
		$('#data-datagrid').datagrid('reload',option);
	});
	
	
	
	function add0(m){return m<10?'0'+m:m }
	function format(shijianchuo){
	//shijianchuo是整数，否则要parseInt转换
		var time = new Date(shijianchuo);
		var y = time.getFullYear();
		var m = time.getMonth()+1;
		var d = time.getDate();
		var h = time.getHours();
		var mm = time.getMinutes();
		var s = time.getSeconds();
		return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
	}
	
	
	
	
	
	/** 
	* 载入数据
	*/
	$('#data-datagrid').datagrid({
		url:'list',
		rownumbers:true,
		singleSelect:false,
		pageSize:20,           
		pagination:true,
		multiSort:true,
		fitColumns:true,
		idField:'id',
		fit:true,
		columns:[[
			{ field:'chk',checkbox:true},
			{ field:'id',title:'订单id',width:100,sortable:true},
			{ field:'item',title:'订单商品详情',width:300},
			{ field:'price',title:'订单价格',width:100},
			{ field:'account.realname',title:'用户姓名',width:100,formatter:formatterPoint},
			{ field:'account.phone',title:'用户电话',width:100,formatter:formatterPoint},
			{ field:'address',title:'用户地址',width:200},
			{ field:'time',title:'下单时间',width:100,align:'center',formatter:function(value,row,index){
				return format(value);
			}}
		]]
	});
</script>